import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';

class DeviceUniqueIdUtil {
  static Future<WindowsDeviceInfo?> getUniqueId() async {
    if (isWindows()) {
      try {
        // 尝试使用 device_info_plus 获取设备 ID
        final deviceInfo = DeviceInfoPlugin();
        final windowsInfo = await deviceInfo.windowsInfo;
        print('windowsInfo: ${windowsInfo.toMap().toString()}');
        return windowsInfo;
      } catch (e, stackTrace) {
        // 如果失败，则使用 win32 包获取 MachineGuid
        // 可以考虑记录日志: logger.e('Failed to get Windows device ID, falling back to MachineGuid', e, stackTrace);
        // return WindowsDeviceIdUtil.getMachineGuid();
      }
    }
    // 其他平台的处理
    return null;
  }

  static bool isWindows() {
    // 判断是否为 Windows 平台
    // 根据 Flutter 标准方式实现
    return Platform.isWindows;
  }
}


//{
//   "computerName": "DESKTOP-C5QJUUA",
//   "numberOfCores": 12,
//   "systemMemoryInMegabytes": 65536,
//   "userName": "97859",
//   "majorVersion": 10,
//   "minorVersion": 0,
//   "buildNumber": 26100,
//   "platformId": 2,
//   "csdVersion": "",
//   "servicePackMajor": 0,
//   "servicePackMinor": 0,
//   "suitMask": 256,
//   "productType": 1,
//   "reserved": 0,
//   "buildLab": "26100.ge_release.240331-1435",
//   "buildLabEx": "26100.1.amd64fre.ge_release.240331-1435",
//   "digitalProductId": [
//     164, 0, 0, 0, 3, 0, 0, 0, 48, 48, 51, 51, 48, 45, 56, 48, 48, 48, 48, 45, 48, 48, 48, 48, 48, 45, 65, 65, 52, 49, 51,
//     0, 236, 12, 0, 0, 91, 84, 72, 93, 88, 49, 57, 45, 57, 56, 56, 52, 49, 0, 0, 0, 236, 12, 0, 0, 0, 0, 168, 210, 123,
//     110, 137, 129, 79, 109, 9, 0, 0, 0, 0, 0, 224, 81, 228, 103, 77, 238, 68, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//     0, 0, ......
//   ],
//   "displayVersion": "24H2",
//   "editionId": "Professional",
//   "installDate": "2025-03-26 19:13:46.000",
//   "productId": "00330-80000-00000-AA413",
//   "productName": "Windows 11 Pro",
//   "registeredOwner": "978599733@qq.com",
//   "releaseId": "2009",
//   "deviceId": "{DE3515B5-E59E-481D-9996-790D394299EB}"
// }
